function strStr(haystack: string, needle: string): number {
    // 长度太长找不到
    if (needle.length > haystack.length) return -1;
    // 空串 返回0
    if (!needle.length) return 0;

    let hay = 0;
    let need = 0;
    let result = -1

    while (hay < haystack.length) {
        // console.log(haystack[hay], needle[need])
        if (haystack[hay] === needle[need]) {

            // 相同
            hay++;
            need++;
            // if(need === needle.length) {
            //     result =  hay - needle.length; 
            //     break;
            // }
        } else if (need && haystack[hay] !== needle[need]) {
            need = 0;
            // console.log("回溯",hay)
            // while (haystack[hay] !== needle[need] && hay > 0) {
            //     console.log(haystack[hay] !== needle[need])
            //     // console.log(haystack[hay], needle[need])
            //     hay--;
            // }
            while (haystack[hay]!== needle[need] && hay > 0) {
                --hay;
                console.log('???',haystack[hay], needle[need] )
            }
        } else {
            hay++;
        }
        // console.log(hay)
    }

    return result;
};

const haystack = "mississippi", needle = "issip"
console.log(strStr(haystack, needle))